{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 根据entity生成一些前后台的代码片段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{'品种ID': 'varietyId',\n '品种名称': 'varietyName',\n '合约': 'contractNo',\n '收盘价': 'closePrice',\n '结算价': 'settlePrice',\n '更新时间': 'updateTime'}"
     },
     "metadata": {},
     "execution_count": 64
    }
   ],
   "source": [
    "# 读取数据\n",
    "with open('open.txt','r',encoding='utf-8') as f:\n",
    "    dataArr = f.readlines()\n",
    "    # print(dataArr)\n",
    "    sData = ''     \n",
    "    for i in dataArr:\n",
    "      sData += i.strip()\n",
    "    arr = sData.split(';')\n",
    "    dict = {}\n",
    "    for i in arr:\n",
    "      if (i.find('/*** ') >= 0):\n",
    "        s1 = 'private '\n",
    "        w1 = i.find(s1) + len(s1)\n",
    "        field = i[i.find(' ', w1) + 1: ]\n",
    "        title = i[i.find('/***') + len('/***:'): i.find('*/')]\n",
    "        # print(field)\n",
    "        # print(title)\n",
    "        dict[title] = field\n",
    "dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "varietyId: 'varietyId',\nvarietyName: 'varietyName',\ncontractNo: 'contractNo',\nclosePrice: 'closePrice',\nsettlePrice: 'settlePrice',\nupdateTime: 'updateTime',\n\n"
    }
   ],
   "source": [
    "# 前端多语言（英文）\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "    key = d\n",
    "    value = str(x)\n",
    "    ret = ret + value + ': \\'' + value + '\\',\\n'  \n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "varietyId: '品种ID',\nvarietyName: '品种名称',\ncontractNo: '合约',\nclosePrice: '收盘价',\nsettlePrice: '结算价',\nupdateTime: '更新时间',\n\n"
    }
   ],
   "source": [
    "# 前端多语言（中文）\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "    key = d\n",
    "    value = str(x)\n",
    "    ret = ret + value + ': \\'' + key + '\\',\\n'  \n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "<el-table-column label=\"品种ID\" prop=\"varietyId\" min-width=\"80\" align=\"left\"></el-table-column>\n<el-table-column label=\"品种名称\" prop=\"varietyName\" min-width=\"80\" align=\"left\"></el-table-column>\n<el-table-column label=\"合约\" prop=\"contractNo\" min-width=\"80\" align=\"left\"></el-table-column>\n<el-table-column label=\"收盘价\" prop=\"closePrice\" min-width=\"80\" align=\"left\"></el-table-column>\n<el-table-column label=\"结算价\" prop=\"settlePrice\" min-width=\"80\" align=\"left\"></el-table-column>\n<el-table-column label=\"更新时间\" prop=\"updateTime\" min-width=\"80\" align=\"left\"></el-table-column>\n\n"
    }
   ],
   "source": [
    "# 前端列表\n",
    "# ret += '\\n\\n'\n",
    "# <el-table-column label=\"品种\" prop=\"productName\" min-width=\"80\" align=\"left\"></el-table-column>\n",
    "# :label=\"$t('base.futureproduct.fproductName')\"\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "  key = d\n",
    "  value = str(x)\n",
    "  ret = ret + '<el-table-column label=\"'+ key +'\" prop=\"' + value + '\" min-width=\"80\" align=\"left\"></el-table-column>\\n' \n",
    "  # ret = ret + '<el-table-column :label=\"$t(\\'base.quoteDockLog.' + value + '\\')\" prop=\"' + value + '\" min-width=\"80\" align=\"left\"></el-table-column>\\n' \n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "dto.setVarietyId(\"varietyId\");\ndto.setVarietyName(\"varietyName\");\ndto.setContractNo(\"contractNo\");\ndto.setClosePrice(\"closePrice\");\ndto.setSettlePrice(\"settlePrice\");\ndto.setUpdateTime(\"updateTime\");\n\n"
    }
   ],
   "source": [
    "# 后台假数据\n",
    "# dto.setFuncDescription(\"funcDescription\");\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "    key = d\n",
    "    value = str(x)\n",
    "    ret = ret + 'dto.set' + value[:1].upper() + value[1:] + '(\"' + value + '\");\\n'\n",
    "print(ret)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "<!-- 品种ID -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.varietyId')\" prop=\"varietyId\"> <el-input v-model=\"saveObj.varietyId\"></el-input> </el-form-item> </div> </el-col>\n<!-- 品种名称 -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.varietyName')\" prop=\"varietyName\"> <el-input v-model=\"saveObj.varietyName\"></el-input> </el-form-item> </div> </el-col>\n<!-- 合约 -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.contractNo')\" prop=\"contractNo\"> <el-input v-model=\"saveObj.contractNo\"></el-input> </el-form-item> </div> </el-col>\n<!-- 收盘价 -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.closePrice')\" prop=\"closePrice\"> <el-input v-model=\"saveObj.closePrice\"></el-input> </el-form-item> </div> </el-col>\n<!-- 结算价 -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.settlePrice')\" prop=\"settlePrice\"> <el-input v-model=\"saveObj.settlePrice\"></el-input> </el-form-item> </div> </el-col>\n<!-- 更新时间 -->\n<el-col :span=\"12\"> <div> <el-form-item :label=\"$t('base.quoteDockLog.updateTime')\" prop=\"updateTime\"> <el-input v-model=\"saveObj.updateTime\"></el-input> </el-form-item> </div> </el-col>\n\n"
    }
   ],
   "source": [
    "# 输入框\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "  key = d\n",
    "  value = str(x)\n",
    "  ret += '<!-- ' + key + ' -->\\n'\n",
    "  ret +=  '<el-col :span=\"12\"> <div> <el-form-item :label=\"$t(\\'base.quoteDockLog.' + value + '\\')\" prop=\"' + value + '\"> <el-input v-model=\"saveObj.' + value + '\"></el-input> </el-form-item> </div> </el-col>\\n'\n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "// 品种ID\nvarietyId: [{ required: true, message: this.$t('base.quoteDockLog.varietyId') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n// 品种名称\nvarietyName: [{ required: true, message: this.$t('base.quoteDockLog.varietyName') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n// 合约\ncontractNo: [{ required: true, message: this.$t('base.quoteDockLog.contractNo') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n// 收盘价\nclosePrice: [{ required: true, message: this.$t('base.quoteDockLog.closePrice') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n// 结算价\nsettlePrice: [{ required: true, message: this.$t('base.quoteDockLog.settlePrice') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n// 更新时间\nupdateTime: [{ required: true, message: this.$t('base.quoteDockLog.updateTime') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n\n"
    }
   ],
   "source": [
    "# ret += '\\n\\n'\n",
    "# organId: [{ required: true, message: this.$t('contract.contractInfo.product') + this.$t('pay.canNotBeBlank'), trigger: ['blur', 'change'] }],\n",
    "# 必输验证\n",
    "ret = ''\n",
    "for (d,x) in dict.items():\n",
    "  key = d\n",
    "  value = str(x)\n",
    "  ret += '// ' + key + '\\n'\n",
    "  ret += value + ': [{ required: true, message: this.$t(\\'base.quoteDockLog.' + value + '\\') + this.$t(\\'pay.canNotBeBlank\\'), trigger: [\\'blur\\', \\'change\\'] }],\\n'\n",
    "print(ret)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37164bit8719ae96e4cc4b4bb775bda64dd4d4db",
   "display_name": "Python 3.7.1 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}